module MatrixOperation

contains

    pure function Determinant2(A) result (v)
        implicit none
        real(kind=8), dimension(2,2), intent(in) :: A

        real(kind=8) :: v

        v = A(1,1) * A(2,2) - A(1,2) * A(2,1)
    end function

    pure subroutine Invert2(A)
        implicit none
        real(kind=8), dimension(2,2), intent(inout) :: A

        real(kind=8) :: det, swap

        det = Determinant2(A)

        swap = A(1,1)
        A(1,1) = -A(2,2)
        A(2,2) = -swap

        A = A / (-det)
    end subroutine
end module
